﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;

namespace MVVMGenerator
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        #region DataBase & Project Configuration

        private void rbtnSQLAuthentication_CheckedChanged(object sender, EventArgs e)
        {
            this.txtUserName.Enabled = this.txtPassword.Enabled = this.rbtnSQLAuthentication.Checked;
            if (!this.rbtnSQLAuthentication.Checked)
                this.txtUserName.Text = this.txtPassword.Text = string.Empty;
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            SqlConnectionStringBuilder csBuilder = new SqlConnectionStringBuilder();
            csBuilder.DataSource = this.txtServer.Text + (string.IsNullOrWhiteSpace(this.txtPortNo.Text) ? "" : "," + this.txtPortNo);
            csBuilder.InitialCatalog = "master";
            csBuilder.IntegratedSecurity = this.rbtnSQLAuthentication.Checked;
            if (this.rbtnSQLAuthentication.Checked)
            {
                csBuilder.UserID = this.txtUserName.Text;
                csBuilder.Password = this.txtPassword.Text;
            }
            SqlConnection connection = new SqlConnection(csBuilder.ConnectionString);
            SqlDataAdapter dbAdapter = new SqlDataAdapter("", connection);
            DataTable dbList = new DataTable();
            dbAdapter.Fill(dbList);
            this.cmbDataBase.DataSource = dbList;
            this.cmbDataBase.SelectedIndex = -1;
        }

        private void cmbDataBase_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btnSavePathBrowse_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
                this.txtSavePath.Text = dlg.SelectedPath;
        }

        #endregion
    }
}
